/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pkl53.view;


import java.awt.CardLayout;
import java.awt.Component;
import java.util.ArrayList;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import pkl53.controller.BackupKuesioner;
import pkl53.controller.KuesionerController;
import pkl53.controller.SubmitControllerPekerjaan;

import pkl53.model.B5Keteranganumumtenagakerjainformal;
import pkl53.model.B6Keteranganumumpekerjaaninformalutama;
import pkl53.model.B7KepalaArt;

/**
 *
 * @author User
 */
public class DataEntriPekerjaanPanel extends javax.swing.JPanel {

    private static int jumlahPekerja;
    private static String KKS;

    /**
     * @return the jumlahPekerja
     */
    public static int getJumlahPekerja() {
        return jumlahPekerja;
    }

    /**
     * @return the KKS
     */
    public static String getKKS() {
        return KKS;
    }

    /**
     * @param aKKS the KKS to set
     */
    public static void setKKS(String aKKS) {
        KKS = aKKS;
    }

    /**
     * @return the jumlahPekerja
     */
    CardLayout card;
    private JPanel panel;
    private KuesionerController kuesionerController;
    private int loop = 1;
    private ArrayList<B5Keteranganumumtenagakerjainformal> b5List = new ArrayList<B5Keteranganumumtenagakerjainformal>();
    private ArrayList<B6Keteranganumumpekerjaaninformalutama> b6List = new ArrayList<B6Keteranganumumpekerjaaninformalutama>();
    private ArrayList<B7KepalaArt> b7List = new ArrayList<B7KepalaArt>();

    /**
     * Creates new form dataEntriPanel
     */
    public DataEntriPekerjaanPanel() {
        initComponents();

//        kuesionerController = new KuesionerController();
//        kuesionerController.setBlok123(blok1231);
//    
//        kuesionerController.setBlok56(blok56);
//        kuesionerController.setBlok67(blok671);
//        kuesionerController.setBlok89(blok789);
//
        blok123.setName("blok123");
        blok4.setName("blok4");
        blok4B.setName("blok4B");
        blok56.setName("blok56");
        blok56B.setName("blok56B");
        blok789.setName("blok789");

    }

    static void setJumlahPekerja(int jp) {
        jumlahPekerja = jp;
    }

    public void setmainFrame(JPanel panel) {
        this.panel = panel;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        backgroundLain1 = new pkl53.imageClass.BackgroundLain();
        jScrollPane1 = new javax.swing.JScrollPane();
        containerPanel = new javax.swing.JPanel();
        blok123 = new pkl53.view.Blok123();
        blok4 = new pkl53.view.Blok4();
        blok4B = new pkl53.view.Blok4B();
        blok56 = new pkl53.view.Blok56();
        blok56B = new pkl53.view.Blok56B();
        blok789 = new pkl53.view.Blok789();
        nextButton = new javax.swing.JButton();
        previousButton = new javax.swing.JButton();
        homeButton = new javax.swing.JButton();
        Save = new javax.swing.JButton();
        Submit = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setPreferredSize(new java.awt.Dimension(1368, 768));

        jScrollPane1.setOpaque(false);
        jScrollPane1.setPreferredSize(new java.awt.Dimension(1070, 1070));

        containerPanel.setBackground(new java.awt.Color(204, 255, 204));
        containerPanel.setOpaque(false);
        containerPanel.setLayout(new java.awt.CardLayout());
        containerPanel.add(blok123, "blok123");
        containerPanel.add(blok4, "blok4");
        containerPanel.add(blok4B, "card7");
        containerPanel.add(blok56, "blok56");
        containerPanel.add(blok56B, "blok56B");
        containerPanel.add(blok789, "blok789");

        jScrollPane1.setViewportView(containerPanel);

        nextButton.setText("Next");
        nextButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nextButtonActionPerformed(evt);
            }
        });

        previousButton.setText("Previous");
        previousButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                previousButtonActionPerformed(evt);
            }
        });

        homeButton.setText("Home");
        homeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                homeButtonActionPerformed(evt);
            }
        });

        Save.setText("Save");
        Save.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SaveActionPerformed(evt);
            }
        });

        Submit.setText("Submit");
        Submit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SubmitActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Data Entri");

        javax.swing.GroupLayout backgroundLain1Layout = new javax.swing.GroupLayout(backgroundLain1);
        backgroundLain1.setLayout(backgroundLain1Layout);
        backgroundLain1Layout.setHorizontalGroup(
            backgroundLain1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(backgroundLain1Layout.createSequentialGroup()
                .addGap(119, 119, 119)
                .addComponent(jLabel1)
                .addContainerGap(1184, Short.MAX_VALUE))
            .addGroup(backgroundLain1Layout.createSequentialGroup()
                .addGroup(backgroundLain1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(backgroundLain1Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(homeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Save, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Submit, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(previousButton, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(nextButton, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(backgroundLain1Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1087, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        backgroundLain1Layout.setVerticalGroup(
            backgroundLain1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, backgroundLain1Layout.createSequentialGroup()
                .addGap(0, 82, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(backgroundLain1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(homeButton)
                    .addComponent(Submit)
                    .addComponent(Save)
                    .addComponent(previousButton)
                    .addComponent(nextButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 623, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(backgroundLain1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(backgroundLain1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void nextButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextButtonActionPerformed
        // TODO add your handling code here:
       
        card = (CardLayout) getContainerPanel().getLayout();
     if (getCurrentCard().getName() != null) {
       if(getCurrentCard().getName().equals("blok123")){
                blok4.setKks(blok123.getB1R1().getText()+
                        blok123.getB1R2().getText()+
                        blok123.getB1R3().getText()+
                        blok123.getB1R4().getText()+
                        blok123.getB1R5a().getText()+
                        blok123.getB1R5b().getText()+
                        blok123.getB1R6().getText() 
                        
                        );
                }}
            
        if (getCurrentCard().getName() != null) {
            
            if (getCurrentCard().getName().equals("blok56B")) {
                
                SubmitControllerPekerjaan setBlok = new SubmitControllerPekerjaan();
                setBlok.setBlok1(blok123);
                setBlok.setBlok4(blok4);
                setBlok.setBlok4B(blok4B);
                setBlok.setBlok56(blok56);
                setBlok.setBlok56B(blok56B);
                setBlok.setBlok789(blok789);
                
                B5Keteranganumumtenagakerjainformal b5 = setBlok.getModelB5();
                B6Keteranganumumpekerjaaninformalutama b6 = setBlok.getModelB6();
                B7KepalaArt b7 = setBlok.getModelB7();
                b5List.add(b5);
                b6List.add(b6);
                b7List.add(b7);
                
                    if (loop < getJumlahPekerja()) {
                        System.out.println("masuk if if");
                        System.out.println("Model belum ditambahkan");
                     //   kuesionerController.resetBlok56();
                        loop++;
                        card.show(getContainerPanel(), "blok56");

//                        DataEntriPekerjaanPanel.getBlok562().getB5R1Nama().requestFocusInWindow();
                        jScrollPane1.getViewport().setViewPosition(new java.awt.Point(0, 0));
                        JOptionPane.showMessageDialog(this, "Lanjut input entri ke-" + loop);
                    } else {
                        System.out.println("masuk if else");
                        JOptionPane.showMessageDialog(this, "Lanjut ke blok 8");
                        card.next(getContainerPanel());
                        jScrollPane1.getViewport().setViewPosition(new java.awt.Point(0, 0));
                    }
            } else if (getCurrentCard().getName().equals("blok789")) {
                System.out.println("masuk else if");
                JOptionPane.showMessageDialog(this, "Sudah selesai. Silakan submit");
            } else {
                System.out.println("masuk else");
                card.next(getContainerPanel());
                jScrollPane1.getViewport().setViewPosition(new java.awt.Point(0, 0));
            }
        } else {
            System.out.println("masuk else terluar");
            card.next(getContainerPanel());
            jScrollPane1.getViewport().setViewPosition(new java.awt.Point(0, 0));
        }
    }//GEN-LAST:event_nextButtonActionPerformed

    private void previousButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_previousButtonActionPerformed
        // TODO add your handling code here:
        card = (CardLayout) getContainerPanel().getLayout();
        card.previous(getContainerPanel());
        jScrollPane1.getViewport().setViewPosition(new java.awt.Point(0, 0));
    }//GEN-LAST:event_previousButtonActionPerformed

    private void homeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_homeButtonActionPerformed
        // TODO add your handling code here:
        int x = JOptionPane.showConfirmDialog(this, "Reset?", "Confirm", 0);
        if (x == 0) {
//            kuesionerController.resetAll();
            card = (CardLayout) panel.getLayout();
            card.show(panel, "homePanel");
        }
    }//GEN-LAST:event_homeButtonActionPerformed

    private void SaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveActionPerformed
        // TODO add your handling code here:
        BackupKuesioner.write();
        JOptionPane.showMessageDialog(this, "Save success!");
    }//GEN-LAST:event_SaveActionPerformed

    private void SubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SubmitActionPerformed
        // TODO add your handling code here:
        
 
        SubmitControllerPekerjaan submit = new SubmitControllerPekerjaan();
        submit.setBlok1(blok123);
        submit.setBlok4(blok4);
        submit.setBlok4B(blok4B);
        submit.setBlok56(blok56);
        submit.setBlok56B(blok56B);
        submit.setBlok789(blok789);
        submit.setB5List(b5List);
        submit.setB6List(b6List);
        submit.setB7List(b7List);
        submit.insertAllBlok();
//        
        JOptionPane.showMessageDialog(null, "belum ada codingan ini tugas prima ");
        

//        
//        
//         
//        
//        
//        B5Keteranganumumtenagakerjainformal b5 = new B5Keteranganumumtenagakerjainformal();
//        b5=blok562.getB5Keteranganumumtenagakerjainformal1();
//        b5.setKKSArtNup("123");
//        
//        System.out.println(b5.getKKSArtNup());
//    
//        
//        OpsiB5r11 b5r11 = new OpsiB5r11(blok562.getB5R11().getText());
//        OpsiB5r13 b5r13 = new OpsiB5r13(blok562.getB5R13().getText());
//        OpsiB5r15 b5r15 = new OpsiB5r15(blok562.getB5R15().getText());
//        OpsiB5r9 b5r9 = new OpsiB5r9(blok562.getB5R9().getText());
//        
//        b5.setB5r11(b5r11);
//        b5.setB5r13(b5r13);
//        b5.setB5r15(b5r15);
//        b5.setB5r9(b5r9);
//        
//        B6Keteranganumumpekerjaaninformalutama b6 = new B6Keteranganumumpekerjaaninformalutama();
////        b6 = blok562.getB6Keteranganumumpekerjaaninformalutama();
//        
//        
//        b6.setKKSArtNup("123");
//        
////        OpsiB6r19 b6r19= new OpsiB6r19(blok671.getB6R19().getText());
////        OpsiB6r17 b6r17 = new OpsiB6r17(blok671.getB6R17().getText());
////        OpsiB6r16 b6r16 = new OpsiB6r16(blok671.getB6R16().getText());
////        OpsiB6r13a b6r13a = new OpsiB6r13a(blok671.getB6R13a().getText());
////        OpsiB6r10 b6r10 = new OpsiB6r10(blok671.getB6R10().getText());
////        OpsiB6r6utamaLain b6R6lain = new OpsiB6r6utamaLain(Integer.parseInt(blok562.getB6R6().getText()));
////       
////        OpsiB6r3 b6r3 = new OpsiB6r3(blok562.getB6R3().getText());
////        OpsiB6r23 b6r23 = new OpsiB6r23(blok671.getB6R22a().getText());
////        
////        b6.setB6r19(b6r19);
////        b6.setB6r17(b6r17);
////        b6.setB6r16(b6r16);
////        b6.setB6r13a(b6r13a);
////        b6.setB6r10(b6r10);
////        b6.setB6R6utama(b6R6lain);
////        b6.setB6R6lain(b6R6lain);
////        b6.setB6r3(b6r3);
////        b6.setB6r23(b6r23);
//        
//        
//        
//        
//        
//        
//        
//        
//        B7KepalaArt b7 = new B7KepalaArt("123");
//        String b7r4 = new String(blok671.getB7Kebahagiaanhidup1().getB7r4());
//        OpsiB7r7 b7r7= new OpsiB7r7(blok671.getB7R7().getText());
//        OpsiB7r6 b7r6 = new  OpsiB7r6(blok671.getB7R6().getText());
//        OpsiB7r5 b7r5 = new OpsiB7r5(blok671.getB7R5().getText());
//        OpsiB7r3 b7r3 = new OpsiB7r3(blok671.getB7R3().getText());
//        OpsiB7r2 b7r2 = new OpsiB7r2(blok671.getB7R2().getText());
//        OpsiB7r1 b7r1 = new OpsiB7r1(blok671.getB7R1().getText());
//        
//        
//        B8Keteranganperumahandanaset b8 = new B8Keteranganperumahandanaset();
//        b8 = blok891.getB8Keteranganperumahandanaset();
//         System.out.println(b8.getB8r10f());
//         b8.setKks("");
//       
//        
//        OpsiB8r7b b8r7b = new OpsiB8r7b(blok891.getB8R7b().getText()); 
//        OpsiB8r7a b8r7a= new OpsiB8r7a(blok891.getB8R7a().getText());
//        OpsiB8r6 b8r6 = new OpsiB8r6(blok891.getB8R6().getText());
//        OpsiB8r5b b8r5b = new OpsiB8r5b(blok891.getB8R5a().getText());
//        OpsiB8r5a b8r5a = new OpsiB8r5a(blok891.getB8R5b().getText());
//        OpsiB8r3 b8r3 = new OpsiB8r3(blok891.getB8R3().getText());
//        OpsiB8r2 b8r2 = new OpsiB8r2(blok891.getB8R2().getText()); 
//        OpsiB8r1 b8r1 = new OpsiB8r1(blok891.getB8R1().getText());
//        OpsiB8r9 b8r9 = new OpsiB8r9(blok891.getB8R9().getText());
//        OpsiB8r8 b8r8 = new OpsiB8r8(blok891.getB8R8().getText());
//        
//        b8.setB8r1(b8r1);
//        b8.setB8r2(b8r2);
//        b8.setB8r3(b8r3);
//        b8.setB8r5a(b8r5a);
//        b8.setB8r5b(b8r5b);
//        b8.setB8r6(b8r6);
//        b8.setB8r7a(b8r7a);
//        b8.setB8r7b(b8r7b);
//        b8.setB8r8(b8r8);
//        b8.setB8r9(b8r9);
//        
//        EntityManagerFactory emf = Persistence.createEntityManagerFactory("pkl53PU");
//        EntityManager em = emf.createEntityManager();
////        
////        em.getTransaction().begin();
////        em.persist(b8);
////        em.persist(b7);
////        em.persist(b5);
////        em.persist(b6);
////        em.getTransaction().commit();
////        em.close();
//        
//        
//        
//        
//        
//        
////        em.getTransaction().begin();
////        //em.persist(b5);
////        em.persist(b8);
////        em.getTransaction().commit();
////        em.close();
        
                
        
        
        
        
        
    }//GEN-LAST:event_SubmitActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Save;
    private javax.swing.JButton Submit;
    private pkl53.imageClass.BackgroundLain backgroundLain1;
    private pkl53.view.Blok123 blok123;
    private pkl53.view.Blok4 blok4;
    private pkl53.view.Blok4B blok4B;
    private pkl53.view.Blok56 blok56;
    private pkl53.view.Blok56B blok56B;
    private pkl53.view.Blok789 blok789;
    private static javax.swing.JPanel containerPanel;
    private javax.swing.JButton homeButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton nextButton;
    private javax.swing.JButton previousButton;
    // End of variables declaration//GEN-END:variables
 

    /**
     * @return the containerPanel
     */
    public static javax.swing.JPanel getContainerPanel() {
        return containerPanel;
    }

    /**
     * @param aContainerPanel the containerPanel to set
     */
    public static void setContainerPanel(javax.swing.JPanel aContainerPanel) {
        containerPanel = aContainerPanel;
    }

    private JPanel getCurrentCard() {
        JPanel card = null;
        for (Component comp : containerPanel.getComponents()) {
            if (comp.isVisible() == true) {
                card = (JPanel) comp;
            }
        }
        return card;
    }
}
